PROJECT=KegScaleMk2
JAL_ROOT=${HOME}/src/jallib-pack-2.4o-0.7.1


#JAL=${JAL_ROOT}/compiler/jalv2
JAL=${HOME}/src/jal/jalv24p-beta/bin/jalv2 -fastmath

OPTS=-s ${JAL_ROOT}/lib -s jallib_extras
HEX=../hex
ifeq (${SIMULATOR}, 1)
  OPTS    := ${OPTS} -include simulator.jal
  PROJECT := ${PROJECT}_sim
endif
PROJECT   := ${PROJECT}_jal

OPTS := ${OPTS} -lst ${HEX}/${PROJECT}.lst \
                -asm ${HEX}/${PROJECT}.asm \
                -codfile ${HEX}/${PROJECT}.cod \
                -hex ${HEX}/${PROJECT}.hex
# More dangerous optimizations (but they reduce code size a bit)
# OPTS=${OPTS} -const-detect -load-reduce -temp-reduce


all: ${HEX}/${PROJECT}.hex

JAL_FILES =	kegscale_mk2.jal \
		button.jal \
		config_bits.jal \
		display.jal \
		eeprom_utils.jal \
		eeprom_init.jal \
		globals.jal \
		io_interface.jal \
		ports.jal \
		simulator.jal \
		utils.jal \
		jallib_extras/strings.jal


${HEX}/${PROJECT}.hex: ${JAL_FILES} Makefile
	mkdir ${HEX} 2> /dev/null || true
	${JAL} ${OPTS} $<
	# Build a .lst file
	mv ${HEX}/${PROJECT}.cod ${HEX}/${PROJECT}.cod.orig
	gpasm ${HEX}/${PROJECT}.asm
	#mv ${HEX}/${PROJECT}.cod.orig ${HEX}/${PROJECT}.cod
